# encoding: utf-8
from flask import session, g
from config import CMS_USER_ID
from .models import CMSUser, CMSPermission
from .views import blueprint



@blueprint.before_request
def before_request():
    if CMS_USER_ID in session:
        id = session.get(CMS_USER_ID)
        user = CMSUser.query.filter_by(id=id).first()
        if user:
            g.cms_user = user

@blueprint.context_processor
def context_processor():
    return {"CMSPermission": CMSPermission}